package m202401.d05;

import java.util.Map;
import java.util.Stack;

/**
 * @@author: 爱做梦的锤子
 * @date: 2024/1/5 09:30
 */
//155. 最小栈
public class Q155 {
    class MinStack {
        Stack<Integer> minStack;
        Stack<Integer> stack;

        public MinStack() {
            this.minStack = new Stack<>();
            this.stack = new Stack<>();
        }

        public void push(int val) {
            this.stack.push(val);
            if (!this.minStack.isEmpty()) {
                this.minStack.push(Math.min(this.minStack.lastElement(), val));
            } else {
                this.minStack.push(val);
            }
        }

        public void pop() {
            if (!this.stack.isEmpty()) {
                this.stack.pop();
            }
            if (!this.minStack.isEmpty()) {
                this.minStack.pop();
            }
        }

        public int top() {
            return this.stack.lastElement();
        }

        public int getMin() {
            return this.minStack.lastElement();
        }
    }
}
